package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.PsychReply;
import com.hs.mapper.PsychReplyMapperr;
import com.hs.service.PsychReplyService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("psyreply")
public class PsychReplyController {
    @Autowired
    private PsychReplyService psychReplyService;
    @PostMapping
    public R addPsychReply(@RequestBody PsychReply psychReply) {
        int i = psychReplyService.addPsychReply(psychReply);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @DeleteMapping("{id}")
    public R deletePsychReply(@PathVariable("id") int id){
        int i = psychReplyService.deletePsychReply(id);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @PutMapping
    public R updatePsychReply(@RequestBody PsychReply psychReply){
        int i = psychReplyService.updatePsychReply(psychReply);
        if (i > 0) {
            return R.ok();
        }
        return R.fail("失败");
    }
    @GetMapping("{id}")
    public R getPsychReplyById(@PathVariable("id") int id){
        PsychReply psychReply = psychReplyService.getPsychReply(id);
        if (psychReply != null) {
            return R.ok(psychReply);
        }
        return R.error("错误");
    }
    @GetMapping("page")
    public R getPsychReplyByPage(PsychReply psychReply,
                                 @RequestParam(required = false,defaultValue = "1") int pageNum,
                                 @RequestParam(required = false,defaultValue = "2") int pageSize){
        PageInfo<PsychReply> PsychReplyByPage =psychReplyService.getPsychReplyByPage(psychReply, pageNum, pageSize);
        return R.ok(PsychReplyByPage);
    }
    @GetMapping
    public R getpsychReplylist(PsychReply psychReply){
        PageInfo<PsychReply> getpsychreplylist = psychReplyService.getpsychreplylist(psychReply);
        return R.ok(getpsychreplylist);
    }
    @GetMapping("sanbiao")
    public R getSanbiao(@RequestParam(required = false,defaultValue = "1") int pageNum,
                        @RequestParam(required = false,defaultValue = "2") int pageSize){
        PageInfo<PsychReply> allByPage = psychReplyService.getAllByPage(pageNum, pageSize);
        return R.ok(allByPage);
    }
    @GetMapping("psychreplyId")
    public R getPsychReplyDuo( int id){
        PsychReply allById = psychReplyService.getAllById(id);
        return R.ok(allById);
    }
    @GetMapping("getPsychReplyByIds/{id}")
    public R getPsychReplyByIds(@PathVariable("id") int id){
        List<PsychReply> psychReplyById = psychReplyService.getPsychReplyById(id);
        return R.ok(psychReplyById);
    }

}
